package com.thyme.system.rest;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.thyme.common.base.ApiResponse;
import com.thyme.system.dao.WytWayBillDao;
import com.thyme.system.entity.WytWaybill;
import io.swagger.annotations.ApiModel;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@ApiModel(value = "发货单控制层")
@RequestMapping("/waybill")
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class WaybillRestController {
    private final WytWayBillDao wytWayBillDao;

    @GetMapping("/list")
    public ApiResponse getUserInfo(@RequestParam("page") int page,
                                   @RequestParam("page_size") int pageSize) {
        JSONObject jsonObject = new JSONObject();
        IPage<WytWaybill> waybillList = null;

        waybillList = wytWayBillDao.getAll(new Page(page, pageSize));


        jsonObject.put("total", waybillList.getTotal());
        jsonObject.put("page", waybillList.getCurrent());
        jsonObject.put("page_size", waybillList.getSize());
        jsonObject.put("waybillList", waybillList.getRecords());
        return ApiResponse.ofSuccess(jsonObject);
    }
}
